package com.my.algorithm;

import com.my.algorithm.entity.*;

import java.math.BigDecimal;

/**
 * 碳数据计算 工具类
 */

public class CarbonCheckUtil {
     public static CarbonCheckUtil checkUtil;

     public static CarbonCheckProductScore setEnergy(CarbonCheckProductEnergy energy){
//          直接燃烧  |固定源 移动源
          if(energy==null)
               return null;
          BigDecimal carbon=new BigDecimal(0),nenghao=new BigDecimal(0);
//          直接燃烧-固定源
          if(energy.getFixedfuelList()!=null){
               for(CarbonCheckProductFixedfuel enity:energy.getFixedfuelList()){
                    if(enity.getNum()==null)
                         enity.setNum(new BigDecimal(0));
                    if(enity.getLowFever()==null)
                         enity.setLowFever(new BigDecimal(0));
                    if(enity.getFeverCarbon()==null)
                         enity.setFeverCarbon(new BigDecimal(0));
                    if(enity.getCorate()==null)
                         enity.setCorate(new BigDecimal(0));
                    carbon=carbon.add(enity.getNum()
                            .multiply(enity.getLowFever())
                            .multiply(enity.getFeverCarbon())
                            .multiply(enity.getCorate()).divide(new BigDecimal(100))
                            .multiply(new BigDecimal(44/12)));
                    nenghao=nenghao.add(enity.getNum().multiply(enity.getLowFever()));
               }
          }
//          直接燃烧-移动源
          if(energy.getMovefuelList()!=null){
               for(CarbonCheckProductMovefuel enity:energy.getMovefuelList()){
                    if(enity.getNum()==null)
                         enity.setNum(new BigDecimal(0));
                    if(enity.getLowFever()==null)
                         enity.setLowFever(new BigDecimal(0));
                    if(enity.getFeverCarbon()==null)
                         enity.setFeverCarbon(new BigDecimal(0));
                    if(enity.getCorate()==null)
                         enity.setCorate(new BigDecimal(0));
                    carbon=carbon.add(enity.getNum()
                            .multiply(enity.getLowFever())
                            .multiply(enity.getFeverCarbon())
                            .multiply(enity.getCorate()).divide(new BigDecimal(100))
                            .multiply(new BigDecimal(44/12)));
                    nenghao=nenghao.add(enity.getNum().multiply(enity.getLowFever()));
               }
          }
//          工业生产过程排放 |碳酸盐
          if(energy.getCarbonateList()!=null){
               for(CarbonCheckProductCarbonate enity:energy.getCarbonateList()){
                    if(enity.getNum()==null)
                         enity.setNum(new BigDecimal(0));
                    if(enity.getFactors()==null)
                         enity.setFactors(new BigDecimal(0));
                    if(enity.getPurity()==null)
                         enity.setPurity(new BigDecimal(0));

                    carbon=carbon.add(enity.getNum()
                            .multiply(enity.getFactors())
                            .multiply(enity.getPurity())
                            .divide(new BigDecimal(100)).negate());
               }
          }
//          废水厌氧处理排放
          if(energy.getWastewaterList()!=null){
               for(CarbonCheckProductWastewater enity:energy.getWastewaterList()){
                    if(enity.getMethaneFactor()==null)
                         enity.setMethaneFactor(new BigDecimal(0));
                    if(enity.getWaterNum()==null)
                         enity.setWaterNum(new BigDecimal(0));
                    if(enity.getSludgeNum()==null)
                         enity.setSludgeNum(new BigDecimal(0));
                    carbon=carbon.add(enity.getMethaneFactor()
                                    .multiply(enity.getWaterNum().subtract(enity.getSludgeNum()))
                                    .multiply(new BigDecimal(0.25*21/1000)).negate());
               }
          }
//          CH4回收与销毁排放
          if(energy.getMethaneList()!=null){
               for(CarbonCheckProductMethane enity:energy.getMethaneList()){
                    if(enity.getOtherNum()==null)
                         enity.setOtherNum(new BigDecimal(0));
                    if(enity.getTorchNum()==null)
                         enity.setTorchNum(new BigDecimal(0));
                    if(enity.getUseNum()==null)
                         enity.setUseNum(new BigDecimal(0));
                    carbon=carbon.add(new BigDecimal(21).
                            multiply(enity.getOtherNum()
                                    .add(enity.getTorchNum())
                                    .add(enity.getUseNum())).negate());
               }
          }
//          CO2回收利用排放量
          if(energy.getCotList()!=null){
               for(CarbonCheckProductCot enity:energy.getCotList()){
                    if(enity.getOtherNum()==null)
                         enity.setOtherNum(new BigDecimal(0));
                    if(enity.getOtherPurity()==null)
                         enity.setOtherPurity(new BigDecimal(0));
                    if(enity.getUseNum()==null)
                         enity.setUseNum(new BigDecimal(0));
                    if(enity.getUsePurity()==null)
                         enity.setUsePurity(new BigDecimal(0));
                    carbon=carbon.add(new BigDecimal(19.77)
                            .multiply(
                                    enity.getOtherNum().multiply(enity.getOtherPurity()).divide(new BigDecimal(100))
                                            .add(enity.getUseNum().multiply(enity.getUsePurity()).divide(new BigDecimal(100))
                    )).negate());
               }
          }
//          固定源净购入电力
          if(energy.getFixedelectricList()!=null){
               for(CarbonCheckProductFixedelectric enity:energy.getFixedelectricList()){
                   nenghao=nenghao.add(new BigDecimal(3.6019).multiply(enity.getNum()));
                    carbon=carbon.add(enity.getNum().multiply(enity.getNum()));
               }
          }
//          固定源净购入热力
          if(energy.getHeatList()!=null){
               for(CarbonCheckProductHeat enity:energy.getHeatList()){
                    nenghao=nenghao.add(enity.getNum());
                    carbon=carbon.add(enity.getNum().multiply(enity.getNum()));
               }
          }
//          移动源净电力
          if(energy.getMovefuelelectricList()!=null){
               for(CarbonCheckProductMovefuelelectric enity:energy.getMovefuelelectricList()){
                    nenghao=nenghao.add(new BigDecimal(3.6019).multiply(enity.getNum()));
                    carbon=carbon.add(enity.getNum().multiply(enity.getNum()));
               }
               }
//          Map<String,BigDecimal> map=new HashMap<>();
//          map.put("nenghao",nenghao);
//          map.put("carbon",carbon);
          CarbonCheckProductScore score=new CarbonCheckProductScore();
          score.setEnergy(nenghao);
          score.setExhaust(carbon);
          score.setProductId(energy.getProductId());
          score.setCheckId(energy.getCheckId());
          return score;
          }


}
